#include "Outlet.h"
#include "string_util.h"
#include "my_def.h"

COutlet::COutlet()
:m_pImage(NULL)
,m_nType(E_OUTLET_MAX)
{
}

COutlet::~COutlet()
{
}

COutlet* COutlet::outletWithType(int nType)
{
	COutlet* pOutlet = new COutlet();
	pOutlet->autorelease();

	if( !pOutlet->initWithType(nType) )
	{
		delete pOutlet;
		pOutlet = NULL;
	}

	return pOutlet;
}

bool COutlet::initWithType(int nType)
{
	if( changeType(nType) )
		m_nType = nType;

	return true;
}

bool COutlet::changeType(int nType)
{
	if( nType >= E_OUTLET_MAX )
		return false;
	
	std::string strFileName ;
	STRING_UTIL::Format( strFileName, "image/outlet/outlet_%d.png",nType);

	if(!m_pImage)
	{
		m_pImage = CCSprite::spriteWithFile(strFileName.c_str());
		m_pImage->setAnchorPoint(ccp(0.5f,0.5f));
		m_pImage->setPosition(CCPointZero);
		addChild(m_pImage);
	}
	else
	{
		m_pImage->setTexture( CCTextureCache::sharedTextureCache()->addImage(strFileName.c_str()) );
	}

	return true;
}